package cn.codeforfun.modules.user.list;

import cn.codeforfun.modules.user.User;
import cn.codeforfun.modules.user.UserService;
import cn.codeforfun.modules.user.list.table.ListTableFrame;
import cn.codeforfun.modules.user.list.table.ListTableModel;
import cn.codeforfun.shared.AbstractFrameController;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Controller;

import java.util.List;

@Controller
@AllArgsConstructor
public class ListController extends AbstractFrameController {
    ListTableFrame tableFrame;
    ListTableModel tableModel;
    UserService userService;

    @Override
    public void prepareAndOpenFrame() {
        loadData();
        tableFrame.setVisible(true);
    }

    private void loadData() {
        List<User> users = userService.findAll();
        tableModel.clear();
        tableModel.addDataList(users);
    }
}
